<?php

class ModelField extends RootClass {
	
	private $name;
	private $alias;
	private $value;
	private $old_value;
	private $changed;
	
	// Constructor class
	function __construct($name,$alias=null,$value=null) {
		// set the field name
		$this->name  = $name;
		// if the alias is null set it to name
		if($alias == null) {
			$this->alias = $name;
		}
		else {
			$this->alias = $alias;
		}
		// set the field value
		$this->value = $value;
		$this->old_value = null;
		
		// Default value to changed
		$this->changed = false;
	}
	
	function getName() {
		return $this->name;
	}

	// Return a name with alias
	function getNameAlias() {	
		$sql = $this->name;
		if($this->alias !=null) {
			$sql .= " as '".$this->alias."' ";
		}
		return $sql;
	}
	
	// Return the alias
	function getAlias() {
		return $this->alias;
	}
	
	// Return the value
	function getValue() {
		if($this->value == null)
			return "null";
		else
			return $this->value;
	}
	
	// Set a new value
	function setValue($value) {
		$this->old_value = $this->value;
		$this->value = $value;
		$this->changed = true;
	}

	// Set a new alias
	function setAlias($alias) {
		$this->alias = $alias;
	}
	
	// Verify if the value was changed
	function isChanged() {
		return $this->changed;
	}
}
?>